package com.sasis.dao.ibatis;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.sasis.dao.UserInfoDAO;
import com.sasis.model.UserInfo;

public class UserInfoDAOImpl  extends BaseDaoiBATIS implements UserInfoDAO {


    private SqlMapClientTemplate template = this.getSqlMapClientTemplate();

	public int deleteByPrimaryKey(UserInfo key) { 
		System.out.println("==========="+key.getId());
		return template.delete("userInfo_deleteByPrimaryKey", key); 
	 
	}
	
	//add by kellen search user by pk
	public UserInfo getUserInfoByPK(String id){
		UserInfo userInfo = null;
		userInfo  = (UserInfo)template.queryForObject("userInfo_searchByPK",id);
		return userInfo;
		
	}
	public UserInfo getUserInfo(String userId, String password) {
		UserInfo userInfo = new UserInfo(); 
		userInfo.setEnName(userId);
		userInfo.setPassword(password);
		List list = template.queryForList("getUserInfo",userInfo); 
		if(null!=list && 0<list.size())
			userInfo = (UserInfo)list.get(0);
		else userInfo = null;
		return userInfo;
	}

	public boolean insert(UserInfo record) {
		Object obj = template.insert("userInfo_insert", record);
		System.out.println(">>>>>insert obj>>>>>"+obj);
		if(null==obj)
			return true;
		else 
			return false;
		
	}

	public UserInfo searchByPrimaryKey(UserInfo record) {
		// TODO Auto-generated method stub
		return null;
	}

	public List select(UserInfo userInfo ) {  
		ArrayList list = (ArrayList)template.queryForList("userInfo_all",userInfo); ;
		return list;
	}

	public int updateByPrimaryKey(UserInfo record) {
		return template.update("userInfo_updateByPrimaryKey", record); 
	}
	//get role all
	public List getRoleAll(){
		UserInfo record = new UserInfo();
		return template.queryForList("userRole_all",record);
	}
	//get right all
	public List getRightAll(){
		UserInfo record = new UserInfo();
		return template.queryForList("userRight_all",record);
	}
 
	public int updateUserRoleRefByPK(UserInfo record){
		return template.update("userRole_updateByUserInfo",record);
	} 
	
	public int updateUserRightRefByPK(UserInfo record){
		return template.update("userRight_updateByUserInfo",record);
	}
	
	public List getUserRoleRefByPK(String seledId){
		UserInfo userInfo = new UserInfo();
		userInfo.setSeledId(seledId);
		return template.queryForList("userRole_selected",userInfo);
	} 
	
	public List getUserRightRefByPK(String seledId){
		UserInfo userInfo = new UserInfo();
		userInfo.setSeledId(seledId);
		return template.queryForList("userRight_selected",userInfo);
	}
	
	public int deleteUserRoleRefByPK(UserInfo record){
		System.out.println(">>>>>>>>>>>>>>>>>>deletected flag.>>>"+record.getSeledId());
		return template.delete("userRole_deleteByUserInfo",record);
	} 
	
	public int deleteUserRightRefByPK(UserInfo record){
		return template.delete("userRight_deleteByUserInfo",record);
	}
	
	
	public List getRoles() {
		// TODO Auto-generated method stub
		return null;
	}
	 
	public List getTopLeaderByUserId(UserInfo record){ 
		return template.queryForList("topLeader_selected",record);
	}

}
